package com.lzy.cloud.account.utils;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 
 * Description:判断 Create by lc Date:Apr 13, 2017 Time:11:25:42 AM
 */
public class CommonsUtil {
	/**
	 * 注释：主要用户mybatis的返回值
	 * 
	 * @param count
	 * @return
	 */
	public static boolean isEmpty(Integer count) {
		return (count == null || count == 0 || count == -1);
	}
	
	/**
	 * 判断字符串是否为空
	 * @param str
	 * @return
	 */
	public static boolean isEmptyString(String str){
		return (str == null || str == "" || "".equals(str.trim()));
	}
	
	/**
	 * 判断long是否为空
	 * @param count
	 * @return
	 */
	public static boolean isEmptyLong(Long count){
		return (count == null);
	}

	/**
	 * 判断Map是否为空
	 * @param map
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public static boolean isEmptyMap(Map map){
		return (map.isEmpty() || map == null);
	}
	
	/**
	 * 判断字符串是否是数字类型
	 * @param str
	 * @return
	 */
	public static boolean isLegalNumber(String str){
		if(!isEmptyString(str)){
			try {
				Double.parseDouble(str);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		return false;
	}
	/**
	 * 判断list集合是否为空
	 * 
	 * @param list
	 * @return
	 */
	public static boolean isEmpty(List list) {
		return (list == null || list.size() == 0);
	}
	
	/**
	 * 验证数字是否合法  --正数且保留两位小数
	 * @param amount
	 * @return
	 */
	public static boolean isLegalAmount(BigDecimal amount){
		if(amount == null) return false;
		String regExp = "^[0-9][0-9]*(\\.[0-9]{1,"+2+"})?$"; //n为小数位数
		Pattern p = Pattern.compile(regExp);  
		Matcher m = p.matcher(amount.toString());  
		return m.matches();  
	}
	/**
	 * 验证数字是否合法  --正数且保留两位小数
	 * @param amount
	 * @return
	 */
	public static boolean isLegalAmountS(String amount){
		if(amount == null) return false;
		String regExp = "^[0-9][0-9]*(\\.[0-9]{1,"+2+"})?$"; //n为小数位数
		Pattern p = Pattern.compile(regExp);  
		Matcher m = p.matcher(amount.toString());  
		return m.matches();  
	}
}
